<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
	<style>
        * {
            padding: 0;
            margin: 0;
        }

        body {
            height: 100vh;
            width: 100vw;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 60px
        }


	</style>
</head>
<body>

<!--在网页中动态显示当前日期和时间，并且网页背景也会随机变色-->

<h1></h1>

<script>

    /**
     * 获取时间的函数，格式为：  2021-1-1 12:20:01
     * @returns {`${number}-${number}-${number} ${number}:${number}:${number}`}
     */
    function showNowTime() {
        let now;
        let date = new Date();
        let Y = date.getFullYear();
        let M = date.getMonth() + 1;
        let D = date.getDate();
        let h = date.getHours();
        let m = date.getMinutes();
        let s = date.getSeconds();
        now = `${Y}-${M}-${D} ${h}:${m}:${s}`;
        return now;
    }

</script>
<script>

    /**
     *
     * 获取m~n之间的随机数
     * @param m：最小值
     * @param n：最大值
     * @returns {number}：随机数
     */
    let getRandom = (m, n) => Math.floor(Math.random() * (n - m + 1) + m);


    /**
     * 获取随机颜色
     * @returns {string}：随机的rgb格式的颜色值
     */
    let randomColor = () => 'rgb(' + getRandom(0, 255) + ',' + getRandom(0, 255) + ',' + getRandom(0, 255) + ')';


</script>
<script>

    const box = document.querySelector('h1');
    const body = document.body;
    setInterval(() => {
        box.innerHTML = showNowTime();
        body.style.backgroundColor = randomColor();
    }, 1000);

</script>

</body>
</html>